﻿using System;
using System.Linq;
using FoodBank.Core.Models;
using FoodBank.Core.Repository;
using FoodBank.Core.Services;

namespace FoodBank.Service
{
    public class UserService : IUserService
    {
        private readonly IRepository<User> _userRepository;
 
        public UserService(IRepository<User> userRepository)
        {
            if (userRepository == null) 
                throw new ArgumentNullException("userRepository");

            _userRepository = userRepository;
        }

        public User GetUser(string userName, string password)
        {
            throw new NotImplementedException();
        }

        public User RegisterUser(string userName, string password, string firstName, string lastName, string email)
        {
            throw new NotImplementedException();
        }

        public bool IsUserNameAlreadyInUse(string userName)
        {
            return _userRepository.RetrieveMany(e => string.Equals(e.UserName, userName, StringComparison.OrdinalIgnoreCase)).Any();
        }

        public bool IsEmailAlreadyRegistered(string email)
        {
            return _userRepository.RetrieveMany(e => string.Equals(e.Email, email, StringComparison.OrdinalIgnoreCase)).Any();
        }
    }
}
